package eval

import (
	"showen7/eval"
	"showen7/inter"
	"showen7/lex"
	"showen7/parse"
	"testing"
)

func TestEvalExpression001(t *testing.T) {
	tests := []struct {
		input string
		want  string
	}{
		{"#t", "#t"},
		{"1", "1"},
		{"1/2", "1/2"},
		{"2/4", "1/2"},
		{"1.23", "1.23"},
		{"1/2+0.34i", "0.5+0.34i"},
		{"#\\A", "#\\A"},
		{"'a", "a"},
		{"'(1 2 3)", "(1 2 3)"},
		{"#(1 2 3)", "#(1 2 3)"},
	}

	env := inter.NewEnvironment()
	eval.RegisterBuiltinProcedures(env)

	for _, tt := range tests {
		lexer := lex.NewLexer(tt.input)
		tokens := lexer.ReadTokens()
		parser := parse.NewParser(tokens)
		expr, err := parser.ParseExpression()
		if err != nil {
			t.Fatalf("parser.ParseExpression() error = %v", err)
		}

		var obj inter.Object
		obj, err = eval.EvalExpression(expr, env)
		if err != nil {
			t.Fatalf("EvalExpression() error = %v", err)
		}
		if obj.Inspect() != tt.want {
			t.Errorf("EvalExpression() = %v, want %v", obj.Inspect(), tt.want)
		}
	}
}
